package com.bw.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Data
@NoArgsConstructor
public class CarVO {


    private Integer uid;

    private String uname;

    private Integer sid;

    private BigDecimal price;

    private String sname;

    private int num;

    private BigDecimal total;

    public static void main(String[] args) {
        Map<String,Integer> map1 = new HashMap<String,Integer>();
        map1.put("2021-01-123-A",100);
        map1.put("2021-02-123-A",500);

        Map<String,Integer> map2 = new HashMap<String,Integer>();
        map2.put("2021-01-123-A",100);
        map2.put("2021-03-123-A",500);


        Map<String,Integer> map3 = new HashMap<String,Integer>();
        map2.put("2021-01-123-A",100);
        map2.put("2021-02-123-A",500);
        Set<Map.Entry<String, Integer>> entries = map1.entrySet();
        Set<Map.Entry<String, Integer>> entries1 = map2.entrySet();
        Set<Map.Entry<String, Integer>> entries2 = map3.entrySet();

        Map<String,Integer> result = new HashMap<String, Integer>();
        for (Map.Entry<String, Integer> entry : entries) {
            for (Map.Entry<String, Integer> stringIntegerEntry : entries1) {
                mapPut(result, entry, stringIntegerEntry);
            }

            for (Map.Entry<String, Integer> stringIntegerEntry : entries2) {
                mapPut(result, entry, stringIntegerEntry);
            }
        }

        for (Map.Entry<String, Integer> stringIntegerEntry : entries1) {
            for (Map.Entry<String, Integer> integerEntry : entries2) {
                mapPut(result, stringIntegerEntry, integerEntry);

            }
        }

        Set<Map.Entry<String, Integer>> entries3 = result.entrySet();
        for (Map.Entry<String, Integer> stringIntegerEntry : entries3) {
            System.out.println(stringIntegerEntry.getKey()+":"+stringIntegerEntry.getValue());
        }


    }

    private static void mapPut(Map<String, Integer> result, Map.Entry<String, Integer> entry, Map.Entry<String, Integer> stringIntegerEntry) {
        if (stringIntegerEntry.getKey().equals(entry.getKey())){
            Integer integer = result.get(stringIntegerEntry.getKey());
            integer = integer ==null?0:integer;
            integer = integer + stringIntegerEntry.getValue()+entry.getValue();
            result.put(stringIntegerEntry.getKey(),integer);
        }else {
            result.put(stringIntegerEntry.getKey(),stringIntegerEntry.getValue());

        }
    }
}
